home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include <stdio.h>
- #include "gl.h"
- /* #include "gl2/gl2cmds.h"
- /****/
-
- #include "geom.h"
- #include "class.h"
- #include "classIds.h"
- #include "selectors.h"
- #include "mbox.h"
- #include "individual.h"
-
- Matrix id = {
- { 1.0, 0.0, 0.0, 0.0, },
- { 0.0, 1.0, 0.0, 0.0, },
- { 0.0, 0.0, 1.0, 0.0, },
- { 0.0, 0.0, 0.0, 1.0, },
- };
-
- extern Matrix gl_pickmat;
-
- typedef struct {
- long comp;
- long num;
- Matrix mat;
- long x,y,z;
- } seg;
-
- typedef struct {
- float x,y,z,w;
- } xfcmd;
-
- typedef struct {
- long component;
- float x,y,z,w;
- float xunit[4];
- long num;
- } fed;
-
- typedef struct {
- long component;
- float unit[8];
- long num;
- } ufed;
-
- #define MAXSEGS 100
- #define FEEDSIZE 5000
-
- static long ocount = 0;
- static long fcount = 0;
- static seg segs[MAXSEGS];
- static fed fedbuf[MAXSEGS];
-
- #ifdef IRIS_3000
- static short rawbuf[FEEDSIZE];
- static char zflag;
- static char depthflag;
- static long oddpt;
- #endif /* IRIS_3000 */
-
- int getfbnm();
- int getfbpt();
-
- initsort()
- {
- #ifdef NOTDEF
- zflag = getzbuffer();
- depthflag = getdcm();
- if(bindfbfunc(FBCxformpt,getfbpt) != TRUE)
- fprintf(stderr,"bindfunc xformpt failed\n");
- setdepth(-5000,5000);
- /*
- bcopy(id,gl_pickmat,sizeof(Matrix));
- */
- oddpt = 0;
- #endif
- }
-
- #ifdef IRIS_3000
- getfbpt(count,command,string,bp)
- int count;
- int command;
- char *string;
- xfcmd *bp;
- {
- register fed *fb = &fedbuf[fcount];
- register int i;
-
- #define FUDGE
- #ifdef FUDGE
- if(!oddpt) {
- fb->component = segs[fcount].comp;
- fb->x = bp->x;
- fb->y = bp->y;
- fb->z = bp->z;
- fb->w = bp->w;
- }
- else {
- fb->num = fcount++;
- fb->xunit[0] = bp->x;
- fb->xunit[1] = bp->y;
- fb->xunit[2] = bp->z;
- fb->xunit[3] = bp->w;
- }
- for(i=0;i<count;i++) getfbword();
- oddpt = !oddpt;
- #else
- fb->component = segs[fcount].comp;
- fb->num = fcount++;
- fb->x = bp->x;
- fb->y = bp->y;
- fb->z = bp->z;
- fb->w = bp->w;
- for(i=0;i<count;i++) getfbword();
- #endif /* FUDGE */
- }
- #endif /* IRIS_3000 */
-
- dolater(ob)
- Object ob;
- {
- register seg *s = &segs[ocount];
-
- s->comp = ob;
- getmatrix(s->mat);
- ocount++;
- if(ocount >= MAXSEGS) {
- fprintf(stderr,"gold: dolater off end of segments\007\n");
- exit(1);
- }
- }
-
- dontdo(ob)
- Object ob;
- {
- register seg *s;
-
- for( s = &segs[0]; s<&(segs[ocount]); s++) {
- if(s->comp == ob) {
- s->comp = 0;
- /* printf("caught one in dontdo()\n"); /* */
- }
- }
- }
- #ifdef IRIS_3000
- #else /* IRIS_3000 */
- void
- transform(Matrix m, int x, int y, int z)
- {
- fedbuf[fcount].component = segs[fcount].comp;
-
- fedbuf[fcount].x = m[0][3] * 1;
- fedbuf[fcount].y = m[1][3] * 1;
- fedbuf[fcount].z = m[2][3] * 1;
- fedbuf[fcount].w = m[3][3] * 1;
-
- fedbuf[fcount].xunit[0] = m[0][0] * x + m[0][1] * y + m[0][2] * z + m[0][3] * 1;
- fedbuf[fcount].xunit[1] = m[1][0] * x + m[1][1] * y + m[1][2] * z + m[1][3] * 1;
- fedbuf[fcount].xunit[2] = m[2][0] * x + m[2][1] * y + m[2][2] * z + m[2][3] * 1;
- fedbuf[fcount].xunit[3] = m[3][0] * x + m[3][1] * y + m[3][2] * z + m[3][3] * 1;
-
- fedbuf[fcount].num = fcount;
- fcount++;
- }
- #endif /* IRIS_3000 */
-
- sortobjs(objid)
- Object objid;
- {
- register fed *fp;
- register seg *s;
- register long i;
- int fedcmp();
-
- #ifdef IRIS_3000
- feedback(rawbuf,FEEDSIZE);;
- for( s = &segs[0]; s<&(segs[ocount]); s++) {
- loadmatrix(s->mat);
- xfpti(0,0,0);
- xfpti(1000,0,0);
- }
- i = endfeedback(rawbuf);
-
- fcount = 0;
- parsefb(rawbuf,i,zflag,depthflag);
- #else /* IRIS_3000 */
- for(fcount = 0, s = &segs[0]; fcount < ocount && s<&(segs[ocount]); s++) {
- transform(s->mat,1000,0,0);
- }
- #endif /* IRIS_3000 */
-
- for(i=0;i<ocount;i++) {
- if(fedbuf[i].w != 0.0)
- fedbuf[i].z = fedbuf[i].z/fedbuf[i].w; /* perspective divide */
- else
- fedbuf[i].z = 100000.0;
- }
- qsort(fedbuf,ocount,sizeof(fedbuf[0]),fedcmp);
-
- makeobj(objid); {
- initnames();
- loadname(0);
- pushname(0);
- pushLongName(objid);
- for(fp = fedbuf;fp<&(fedbuf[ocount]);fp++) {
- loadmatrix(segs[fp->num].mat);
- if(fp->component)
- drawModels(fp->component,((ufed *)fp)->unit); /* does callobj for each Model */
- }
- popLongName();
- }
- closeobj();
- ocount = 0;
- }
-
-
- fedcmp(p1,p2)
- fed *p1, *p2;
- {
- if(p1->z < p2->z) return 1;
- if(p1->z > p2->z) return -1;
- return 0;
- }
-
- spitseg(s)
- seg *s;
- {
- spitmat(s->mat);
- printf("pt:\n %d %d %d\n",s->x,s->y,s->z);
- }
-
- spitfed(fp)
- fed * fp;
- {
- printf("fed: %d pt( %g %g %g %g )num = %d\n",
- fp->component,fp->x,fp->y,fp->z,fp->w,fp->num);
- }
-
- spitmat(s)
- Matrix s;
- {
- register long i,j;
-
- printf("mat:\n");
- for(j=0;j<4;j++) {
- for(i=0;i<4;i++) {
- printf(" %g",s[i][j]);
- }
- printf("\n");
- }
- }
-